package cn.socket;


import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 主机地址
 */
public class InetAddressTest {
    public static void main(String[] args) throws UnknownHostException {
        //通过主机名获得对象
        InetAddress inetAddress=InetAddress.getByName("LAPTOP-VB8QSKVB");
        //得到ip
        String ip = inetAddress.getHostAddress();
        String hostName = inetAddress.getHostName();
        System.out.println("ip:"+ip);
        System.out.println("主机名:"+hostName);
    }
}
